package com.soft.app;

import java.io.File;
import java.io.UnsupportedEncodingException;

import org.webharvest.definition.ScraperConfiguration;
import org.webharvest.runtime.Scraper;

// Referenced classes of package com.social.app:
//			ExecutableJob

public class WebToXml
	implements ExecutableJob
{

	private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(WebToXml.class);
	private java.lang.String config;
	private java.lang.String data;
	private java.lang.Integer start;
	private java.lang.Integer end;
	private boolean debug;
	private org.webharvest.definition.ScraperConfiguration sc;

	public WebToXml(java.lang.String config, java.lang.String data, int start, int end, boolean debug)
	{
		this.config = null;
		this.data = null;
		this.start = null;
		this.end = null;
		this.debug = false;
		this.config = config;
		this.data = data;
		this.start = java.lang.Integer.valueOf(start);
		this.end = java.lang.Integer.valueOf(end);
		this.debug = debug;
	}

	public void execute()
	{
		log.info("开始从WEB提取数据到XML");
		log.info("配置文件:{}", config);
		log.info("工作目录:{}", data);
		log.info("开始年份:{}", start);
		log.info("结束年份:{}", end);
		log.info("debug:{}", Boolean.valueOf(debug));
		sc = null;
		java.io.File f = new File(config);
		try
		{
			sc = new ScraperConfiguration(f);
			if (sc == null)
			{
				log.error("config为空");
				java.lang.System.exit(-1);
			}
		}
		catch (java.io.FileNotFoundException e)
		{
			log.error("配置文件:[{}]未找到.", f.getAbsoluteFile());
			java.lang.System.exit(-1);
		}
		catch (Exception e)
		{
			log.error("编码不多,我写死了utf-8了,{}", e);
			e.printStackTrace();
		}
		for (int i = start.intValue(); i <= end.intValue(); i++)
		{
			org.webharvest.runtime.Scraper scraper = new Scraper(sc, data);
			scraper.addVariableToContext("y", java.lang.String.valueOf(i));
			scraper.setDebug(debug);
			scraper.execute();
		}

	}

	public org.webharvest.definition.ScraperConfiguration getScraperConfiguration()
	{
		return sc;
	}

}